package config

import (
	"log"
	"os"

	"gopkg.in/yaml.v2"
)

type Config struct {
	Consul struct {
		Address string `yaml:"address"`
		Token   string `yaml:"token"`
	} `yaml:"consul"`
	SyncInterval int    `yaml:"sync_interval"`
	Prefix       string `yaml:"prefix"`
}

var config Config

func GetConfig() Config {
	return config
}

// 读取配置文件config.yaml
func InitConfig(file string) {
	// 读取配置文件
	f, err := os.Open(file)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()
	if err := yaml.NewDecoder(f).Decode(&config); err != nil {
		log.Fatal(err)
	}
}
